#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define F first
#define S second
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
const int N=2e5+10;
ll a[N],b[N];
int n,m;

void solve()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=m;i++) cin>>b[i];
	sort(b+1,b+1+m,greater<int>{});
	int d=1;
	for(int i=1;i<=n;i++)
	{
		while(d<=m && b[d]>=a[i])
		{
			cout<<b[d]<<' ';
			d++;
		}
		cout<<a[i]<<' ';
	}
	for(int i=d;i<=m;i++) cout<<b[i]<<' ';
	cout<<'\n';
}
int main()
{
	IOS;
	int T=1;
	cin>>T;

	while(T--)
	{
		solve();
	}

	return 0;
}

